#include <QUuid>
#include <QMessageBox>
#include "cglobal.h"

extern QString createGuid()
{
	// 生成一个新的 UUID
	QUuid uuid = QUuid::createUuid();

	// 将生成的 UUID 转换为二进制数据
	QByteArray uuidBytes = uuid.toRfc4122();

	// 将二进制数据转换为十六进制字符串（无连字符）
	QString uuidString;
	for (int i = 0; i < uuidBytes.size(); ++i)
	{
		uuidString += QString("%1").arg((unsigned char)uuidBytes.at(i), 2, 16, QChar('0'));
	}
	return uuidString;
}

extern int messageBox(int nMsgLevel, QString sMsg)
{
	if (nMsgLevel == 0)
	{
		int nRet = QMessageBox::information(nullptr, QString::fromLocal8Bit("信息"), sMsg);
		return nRet;
	}
	else if (nMsgLevel == 1)
	{
		int nRet = QMessageBox::warning(nullptr, QString::fromLocal8Bit("警告"), sMsg);
		return nRet;
	}
	else if (nMsgLevel == 2)
	{
		int nRet = QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), sMsg);
		return nRet;
	}
	else if (nMsgLevel == 3)
	{
		int nRet = QMessageBox::question(nullptr, QString::fromLocal8Bit("询问"), sMsg, QMessageBox::Yes | QMessageBox::No | QMessageBox::Close);
		return nRet;
	}

	return 0;
}
